package cc.comac.mom.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cc.comac.mom.api.EquipInventoryService;
import cc.comac.mom.bean.EquipInventory;
import cc.comac.mom.bean.EquipInventoryBean;
import cc.comac.mom.bean.ResultDev;
import cc.comac.mom.util.ResultBean;

@RestController
@RequestMapping("/EquipInventory")
public class EquipInventoryController {

	@Autowired
	private EquipInventoryService equipInventoryService;

	// 保存盘点数据
	@RequestMapping(value = "/saveInventoryAndSpareData", method = RequestMethod.POST)
	public ResultBean saveInventoryAndSpareData(@RequestBody EquipInventoryBean equipInventoryBean) {
		ResultBean resultBean = equipInventoryService.saveInventoryAndSpareData(equipInventoryBean);
		return resultBean;
	}

	// 查询数据
	@RequestMapping(value = "/selectBySomeFields", method = RequestMethod.POST)
	public ResultBean selectBySomeFields(@RequestBody EquipInventory equipInventory) {
		ResultBean resultBean = new ResultBean(true);
		try {
			ResultDev selectBySomeFields = equipInventoryService.selectBySomeFields(equipInventory);
			resultBean.setObject(selectBySomeFields);
		} catch (RuntimeException e) {
			resultBean.setErrorMessge(e.getMessage());
			return resultBean;
		}
		return resultBean;
	}

	// 批量删除
	@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
	public ResultBean batchDelete(@RequestBody List<EquipInventory> list) {
		ResultBean resultBean = equipInventoryService.batchDelete(list);

		return resultBean;
	}

	// 盘点确认更新库存
	@RequestMapping(value = "/spareInWarehouseUpdateQuantity", method = RequestMethod.POST)
	public ResultBean spareInWarehouseUpdateQuantity(@RequestBody List<EquipInventory> list) {

		ResultBean resultBean = equipInventoryService.spareInWarehouseUpdateQuantity(list);

		return resultBean;
	}

	// 编辑库存
	@RequestMapping(value = "/updateInventorySpare", method = RequestMethod.POST)
	public ResultBean updateInventorySpare(@RequestBody EquipInventoryBean equipInventoryBean) {
		ResultBean resultBean = equipInventoryService.updateInventorySpare(equipInventoryBean);
		return resultBean;
	}

}
